CC           	  = g++

BOOST_INCLUDE_DIR = /usr/local/include/
BOOST_REGEX_LIB   = -lboost_regex 
BOOST_THREAD_LIB  = -lboost_thread
CFLAGS       	  = -O3 -DDEBUG_LEVEL=DEBUG_VERBOSE $(CUSTOM_DEFS) -DBOOST_REGEX_MATCH_EXTRA 
LFLAGS       	  = -O3 -L/usr/local/lib/

ARCH_LIBS		  = $(BOOST_REGEX_LIB) $(BOOST_THREAD_LIB)
CAP_LIBS    	  = $(shell pkg-config --libs ode)  $(BOOST_THREAD_LIB)
#CAP_LIBS	  =/usr/local/lib
DIST_CAP_LIBS     = -lpthread $(CAP_LIBS) 

BASE_OBJS    	  = main.o popolazione.o Individuo.o common.o GAmodSettings.o SimpleCore.o CLController.o\
			 MultiPopCore.o CoreFactory.o MultiPopCoreMT.o CompactCore.o CompactPop.o MGAcore.o ECGAcore.o\
			 ./ecga/parameter.o ./ecga/utility.o ./ecga/random.o \
 			 ./ecga/cache.o ./ecga/chromosome.o ./ecga/gene.o ./ecga/intlist.o ./ecga/mpm.o ./ecga/objfunc.o \
			./ecga/population.o  ./ecga/subset.o ./ecga/ecga.o
ARCH_OBJS		  = ArchValidator.o
CAP_OBJS		  = CaP_Validator.o
DIST_CAP_OBJS     = DistCaPValidator.o DistCaPProtocol.o

ALL_OBJS		  = $(BASE_OBJS) $(ARCH_OBJS) $(CAP_OBJS) $(DIST_CAP_OBJS) DistCaPClient.o

DGC_OBJS     	  = CaPClient.o $(CAP_OBJS) $(DIST_CAP_OBJS) DistCaPClient.o GAmodSettings.o Individuo.o popolazione.o common.o

DOXYGEN_EXE		  = /Applications/Doxygen.app/Contents/Resources/doxygen
DOXYFILE		  = ArchLUT5Fwk.doxyfile

DEL          	  = rm -f
DEL_DIR	     	  = rm -rd
CP	     	  	  = cp 
MKDIR	     	  = mkdir
ESEGUIBILE   	  = LUT5Fwk
ESEGUIBILEDV 	  = HERA_Client
GPROF        	  = gprof
TAR_CMD	     	  = tar -cvjf
TAR_FILE     	  = ArchLUT5Fwk.tar.bz2
TMP_DIR      	  = ArchLUT5Fwk
FILE_PROF    	  = prof.txt

archlog: CUSTOM_DEFS += -DARCH_LOG
archlog: $(BASE_OBJS) $(ARCH_OBJS)
	$(CC) $(LFLAGS) -o $(ESEGUIBILE) $^ $(ARCH_LIBS)

archcap: CUSTOM_DEFS += -DARCH_CAP
archcap: $(BASE_OBJS) $(CAP_OBJS)
	$(CC) $(LFLAGS) -o $(ESEGUIBILE) $^ $(CAP_LIBS)

archdcap: CUSTOM_DEFS += -DARCH_DCAP
archdcap: $(BASE_OBJS) $(CAP_OBJS) $(DIST_CAP_OBJS)
	$(CC) $(LFLAGS) -o $(ESEGUIBILE) $^ $(DIST_CAP_LIBS)

dist_client: $(DGC_OBJS)
	$(CC) $(LFLAGS) -o $(ESEGUIBILEDV) $(DGC_OBJS) $(CAP_LIBS)

$(ARCH_OBJS): CFLAGS += -I $(BOOST_INCLUDE_DIR) 
$(CAP_OBJS): CFLAGS += $(shell pkg-config --cflags ode)

%.o: %.cpp
	$(CC) $(CFLAGS) -c $< -o $@

include $(subst .o,.d,$(ALL_OBJS))

%.d: %.cpp 
	$(CC) -M $(shell pkg-config --cflags ode) -I $(BOOST_INCLUDE_DIR) $(CUSTOM_DEFS) $< > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$ 

doc: 
	$(DOXYGEN_EXE) $(DOXYFILE)

dist:
	$(MKDIR) $(TMP_DIR)
	$(MKDIR) $(TMP_DIR)/snap
	$(MKDIR) $(TMP_DIR)/trainSet
	$(MKDIR) $(TMP_DIR)/utils
	$(CP) *.hpp $(TMP_DIR)/
	$(CP) *.cpp $(TMP_DIR)/
	$(CP) utils/*.py $(TMP_DIR)/utils
	$(CP) trainSet/*.txt $(TMP_DIR)/trainSet
	$(CP) prova.cnf	$(TMP_DIR)/
	$(CP) Makefile $(TMP_DIR)/
	$(CP) ArchLUT5Fwk.doxyfile $(TMP_DIR)/
	$(TAR_CMD) $(TAR_FILE) $(TMP_DIR)/
	$(DEL_DIR) $(TMP_DIR)/

prof:	$(ESEGUIBILE)
	$(ESEGUIBILE)
	$(GPROF) $(ESEGUIBILE) > $(FILE_PROF)

clean:
	$(DEL) *.o
	$(DEL) ./ecga/*.o
	$(DEL) *.d
	$(DEL) ./ecga/*.d
	$(DEL) $(ESEGUIBILE)
	$(DEL) $(ESEGUIBILEDV)
	$(DEL) gmon.out

clean_snap:
	$(DEL) snap/*.txt
	$(DEL) snap/*.dat

clean_all: clean clean_snap
